package entity;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.CascadeType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author Chenhui
 */
@Entity
public class PortfolioEntity implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private String name;
    private String timeCreated;
    private String timeValuated;
    private float value;
    private String type;
    private float gains;
    private float risk;
    
    @ManyToOne(cascade={CascadeType.PERSIST})
    private ClientEntity client;
    
    @OneToMany(cascade={CascadeType.PERSIST})
    private Collection<PortfolioEntryEntity> portfolioEntry=new ArrayList<PortfolioEntryEntity>();
    
    public PortfolioEntity(){}
    
    public void create(String name,String type){
        this.setName(name);
        this.setTimeCreated();
        this.setType(type);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTimeCreated() {
        return timeCreated;
    }

    public void setTimeCreated() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        this.timeCreated = dateFormat.format(new Date());
    }


    public String getTimeValuated() {
        return timeValuated;
    }

    public void setTimeValuated(String timeValuated) {
        this.timeValuated = timeValuated;
    }

    public float getValue() {
        return value;
    }

    public void setValue(float value) {
        this.value = value;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public float getGains() {
        return gains;
    }

    public void setGains(float gains) {
        this.gains = gains;
    }

    public float getRisk() {
        return risk;
    }

    public void setRisk(float risk) {
        this.risk = risk;
    }

    public ClientEntity getClient() {
        return client;
    }

    public void setClient(ClientEntity client) {
        this.client = client;
    }

    public Collection<PortfolioEntryEntity> getPortfolioEntry() {
        return portfolioEntry;
    }

    public void setPortfolioEntry(Collection<PortfolioEntryEntity> portfolioEntry) {
        this.portfolioEntry = portfolioEntry;
    }
}
